package com.fengmi.controller;

import com.fengmi.dto.PageDTO;
import com.fengmi.entity.MallGoodsBrand;
import com.fengmi.entity.SysUser;
import com.fengmi.service.IMallGoodsBrandService;
import com.fengmi.service.impl.MallGoodsBrandService;
import com.fengmi.vo.PageResultVO;
import com.fengmi.vo.ResultVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 作者：陈学虎
 * 时间：2021/7/6 0006 下午 6:02
 */
@RestController
@RequestMapping("brands")
@CrossOrigin
@Api(description = "商品品牌信息")
public class MallGoodsBrandController {

    @Autowired
    private IMallGoodsBrandService mallGoodsBrandService;

    @GetMapping("/findOne")
    @ApiOperation("查找指定的品牌")
    public ResultVO findOne(@ApiParam("查找品牌的id") Integer id){
        return mallGoodsBrandService.findOne(id);
    }

    @PostMapping("/findAll")
    @ApiOperation("分页条件查询")
    @PreAuthorize("hasAnyRole('ROLE_BZR')")
    public PageResultVO<MallGoodsBrand> findAll(@RequestBody @ApiParam("分页参数dto") PageDTO<MallGoodsBrand> pageDTO){

        return mallGoodsBrandService.findBrandByWhere(pageDTO);
    }

    @DeleteMapping("/delById/{id}")
    @ApiOperation("删除指定的品牌")
    public ResultVO delById(@PathVariable("id") @ApiParam("要删除品牌的id") Integer id){
        return mallGoodsBrandService.delById(id);
    }

    @PostMapping("/addBrand")
    @ApiOperation("添加指定的品牌")
    public ResultVO addBrand(@RequestBody @ApiParam("要添加品牌的具体信息") MallGoodsBrand mallGoodsBrand){
        return mallGoodsBrandService.addBrand(mallGoodsBrand);
    }

    @PostMapping("/updateBrand")
    @ApiOperation("修改指定的品牌信息")
    public ResultVO updateBrand(@RequestBody @ApiParam("要修改品牌的具体信息") MallGoodsBrand mallGoodsBrand){
        return mallGoodsBrandService.updateBrand(mallGoodsBrand);
    }

    @PostMapping("/delBactch")
    @ApiOperation("批量删除商品")
    public ResultVO delBactch(@RequestBody @ApiParam("要删除的品牌") List<MallGoodsBrand> mallGoodsBrandList){
        return mallGoodsBrandService.delBactch(mallGoodsBrandList);
    }

    @GetMapping("/findAll")
    @ApiOperation("查询所有的商品")
//    @PreAuthorize("hasAnyAuthority('student_list1')")
    @PreAuthorize("hasAnyRole('ROLE_BZR')")
    public ResultVO findAll(){
        //获取用户id

        return mallGoodsBrandService.findAll();
    }

}
